/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFAmpCh
  \brief abstract base class for a general raw data channel
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-09-27
  \date 2023-10-27 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date        <th>Author      <th>Description                    </tr>
  <tr>  <td>2021-09-27   <td>Asia Sun    <td>file created                   </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFAmpCh_h
#define ETFAmpCh_h

#include <vector>
#include "ETFRawChannel.h"

using std::vector;

class ETFAmpCh : public ETFRawChannel{
public:
  ETFAmpCh();
  ETFAmpCh(const ETFAmpCh &ach);
  virtual ~ETFAmpCh();

  double GetAmplitude(int i = 0) const;
  double value(int i = 0) const{ return GetAmplitude(i); }
  const vector<double> &GetAmplitudeVec() const{ return va; }
  int GetNofValues() const{ return va.size(); }
  int nv() const{ return va.size(); }

  // for dual range value selection - the optimal one would be put in the 1st
  bool ov() const{ return fOverflow; }
  bool un() const{ return fUnderflow; }
  bool rg() const{ return fRange; }
  void SetOverflow(bool opt = true){ fOverflow = opt; }
  void SetUnderflow(bool opt = true){ fUnderflow = opt; }
  void SetRange(bool low){ fRange = low; }

  virtual void SetAmplitude(double amp, int i = 0); ///< assign i-th value in channel number
  virtual void AddAmplitude(double amp); ///< add a amplitude in channel number
  virtual void SetAmplitude(double amp, int rg, bool ov, bool un);

  virtual void Reset() override;
  virtual void Print(const char *opt = "") const override;
  virtual bool good() const{ return !fOverflow && !fUnderflow; }

  ClassDefOverride(ETFAmpCh, 1); // to hold an amplitude ch

protected:
  vector<double> va;
  bool fOverflow, fUnderflow; ///< of the last assigned value
  bool fRange; //! range: 0: high; 1: low -- of the last assigned value
};

#endif
